package cn.edu.scau.cmi.zengGuanSheng.springAndhibernate.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import cn.edu.scau.cmi.zengGuanSheng.springAndhibernate.domain.Student;
import cn.edu.scau.cmi.zengGuanSheng.springAndhibernate.util.HibernateSessionFactoryUtil;

public class StudentDao {
	
	//添加学生
	public void addStu(Student stu) {
		Session s = HibernateSessionFactoryUtil.getSession();
		s.save(stu);
		HibernateSessionFactoryUtil.commitTransactionAndClose(s);
	}
	
	//列出所有学生信息
	public List<Student> listStu(){
		Session s = HibernateSessionFactoryUtil.getSession();
		Query q =s.createQuery("from Student stu");
		List<Student> listOfStudent = q.list();
		HibernateSessionFactoryUtil.commitTransactionAndClose(s);
		return listOfStudent;
	}
	
	//删除学生
	public void deleteStu(Student stu) {
		//没有这个业务需求，暂不实现
	}
	
	//修改学生
	public void editStu(Student stu) {
		//没有这个业务需求，暂不实现
	}

}
